/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package mnstudent.dataacesslayer;
import mnstudent.datatranferobject.ListSubjectOpenDTO;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
/**
 *
 * @author lee
 */
public class ListSubjectOpenDAL {
    
    //<editor-fold defaultstate="collapsed" desc="Attributes">
    private ListSubjectOpenDTO m_ListSubjectOpenObj;
    private DataExecuteUseStoreProcedure m_DataExecute;
    private String  m_sqlCmd;
    
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="Constuctor">
    public ListSubjectOpenDAL(){
        this.m_ListSubjectOpenObj = new ListSubjectOpenDTO();
        this.m_DataExecute = new DataExecuteUseStoreProcedure();    
        this.m_sqlCmd = "";
    }
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="Method">
    
    public ResultSet getAllSubjectWithKindOfSubject()
    {
        try
        {
            m_sqlCmd = "{Call GetAllSubjectWithKindOfSubjectFromDatabase}";
            ResultSet _rsData = this.m_DataExecute.getDataFromDatabase(m_sqlCmd, null);
            return _rsData;
        }catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return null;
    }
     /**
     * Ham lay tat ca cac khoa
     *
     * @return ResultSet
     */
    public ResultSet getAllListSubjectOpenBySemesterYear(String _idYear, String _idSemester){
        try
        {
            m_sqlCmd = "{Call GetAllListSubjectOpenBySemesterYearFromDatabase(?,?)}";
            String[] arrStr= {_idYear, _idSemester};
            ResultSet _rsData = this.m_DataExecute.getDataFromDatabase(m_sqlCmd, arrStr);
            return _rsData;
        }catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return null;
    }
    
     /**
     * ham them moi khoa xuong database
     * @param _listSubjectOpen
     * @return true: success, false: fail
     */
    public boolean insertListSubjectOpenToDatabase(ListSubjectOpenDTO _listSubjectOpen)
    {
       try {
           m_sqlCmd = "{Call InsertListSubjectOpenToDatabase(?,?, ?)}";
           String[] arrStr = {_listSubjectOpen.getAcademicYearID(), _listSubjectOpen.getSemesterID(), _listSubjectOpen.getSubjectID()};

           return this.m_DataExecute.updateDataToDatabase(m_sqlCmd,arrStr)>0;
           
       } catch (Exception ex) {
          ex.printStackTrace();
       }
        return false;
    }
    
    /**
     * Ham cap nhat sua doi thong tin khoa
     * @param _listSubjectOpen
     * @return tue: thanh cong, false: that bai
     */
    public boolean updateListSubjectOpenToDatabase(ListSubjectOpenDTO _listSubjectOpen)
    {
       try {
           m_sqlCmd = "{Call UpdateListSubjectOpenToDatabase(?,?,?)}";
           String[] arrStr = {_listSubjectOpen.getAcademicYearID(), _listSubjectOpen.getSemesterID(), _listSubjectOpen.getSubjectID()};

           return this.m_DataExecute.updateDataToDatabase(m_sqlCmd,arrStr)>0;
           
       } catch (Exception ex) {
          ex.printStackTrace();
       }
        return false;
    }
    
    /**
     * Ham xoa mot khoa ra khoi database
     * @param _listSubjectOpen
     * @return 
     */
     public boolean deleteListSubjectOpenFromDatabase(ListSubjectOpenDTO _listSubjectOpen)
    {
        try {
           m_sqlCmd = "{Call DeleteListSubjectOpenToDatabase(?,?,?)}";
           String[] arrStr = {_listSubjectOpen.getAcademicYearID(), _listSubjectOpen.getSemesterID(), _listSubjectOpen.getSubjectID()};

           return this.m_DataExecute.updateDataToDatabase(m_sqlCmd, arrStr)>0;
           
       } catch (Exception ex) {
          ex.printStackTrace();
       }
        return false;
    }
     
    public boolean deleteListSubjectOpenBySemesterYearFromDatabase(String _idYear, String _idSemester)
    {
        try {
           m_sqlCmd = "{Call DeleteListSubjectOpenBySemesterYearToDatabase(?,?)}";
           String[] arrStr = {_idYear, _idSemester};

           return this.m_DataExecute.updateDataToDatabase(m_sqlCmd, arrStr)>0;
           
       } catch (Exception ex) {
          ex.printStackTrace();
       }
        return false;
    }
    //</editor-fold>
}
